home *** CD-ROM | disk | FTP | other *** search
/ Aminet 51 / Aminet 51 (2002)(GTI - Schatztruhe)[!][Oct 2002].iso / Aminet / util / arc / xadmasterdev.lha / xad / Sources / clients / xMash.c < prev   
Encoding:
C/C++ Source or Header  |  2002-08-20  |  4.9 KB  |  203 lines

  1. #ifndef XADMASTER_XMASH_C
  2. #define XADMASTER_XMASH_C
  3.  
  4. /* Programmheader
  5.  
  6.     Name:        xMash.c
  7.     Main:        xadmaster
  8.     Versionstring:    $VER: xMash.c 1.4 (29.08.1999)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    xMash disk archiver client
  12.  
  13.  1.0   05.09.98 : first version
  14.  1.1   04.02.99 : added new InfoText system
  15.  1.2   20.06.99 : removed exec.library calls
  16.  1.3   29.06.99 : now uses master free stuff
  17.  1.4   29.08.99 : now uses xdi_DataPos
  18. */
  19.  
  20. #include <proto/xadmaster.h>
  21. #include "SDI_compiler.h"
  22. #include "xadXPK.c"
  23.  
  24. #ifndef XADMASTERFILE
  25. #define xMash_Client        FirstClient
  26. #define NEXTCLIENT        0
  27. #define XADMASTERVERSION    8
  28. UBYTE version[] = "$VER: xMash 1.4 (29.08.1999)";
  29. #endif
  30. #define XMASH_VERSION        1
  31. #define XMASH_REVISION        4
  32.  
  33. /*
  34.   structure of one xMash chunk:
  35.     UBYTE        xmc_Type;
  36.     UBYTE        xmc_Start
  37.     UBYTE        xmc_Num;
  38.     ULONG        xmc_Size;
  39. */
  40.  
  41. #define XMASH_INFOTEXT    0x46
  42. #define XMASH_BANNER    0x42
  43. #define XMASH_ARCHIVE    0x44
  44.  
  45. struct xMashHead {
  46.   UBYTE    type;
  47.   UBYTE start;
  48.   UBYTE num;
  49. };
  50.  
  51. ASM(BOOL) xMash_RecogData(REG(d0, ULONG size), REG(a0, STRPTR data),
  52. REG(a6, struct xadMasterBase *xadMasterBase))
  53. {
  54.   if(data[0] == 'M' && data[1] == 'S' && data[2] == 'H' &&
  55.   (data[3] == XMASH_BANNER || data[3] == XMASH_ARCHIVE || data[3] ==
  56.   XMASH_INFOTEXT))
  57.     return 1;
  58.   else
  59.     return 0;
  60. }
  61.  
  62. ASM(LONG) xMash_GetInfo(REG(a0, struct xadArchiveInfo *ai),
  63. REG(a6, struct xadMasterBase *xadMasterBase))
  64. {
  65.   LONG err, lowcyl = 80, highcyl = -1;
  66.   ULONG dat[9], start = 3;
  67.   struct xadDiskInfo *xdi;
  68.   struct xadTextInfo *ti = 0;
  69.   struct xMashHead h;
  70.  
  71.   if(!(xdi = (struct xadDiskInfo *) xadAllocObjectA(XADOBJ_DISKINFO, 0)))
  72.     return XADERR_NOMEMORY;
  73.   ai->xai_DiskInfo = xdi;
  74.  
  75.   xdi->xdi_EntryNumber = 1;
  76.   xdi->xdi_SectorSize = 512;
  77.   xdi->xdi_Cylinders = 80;
  78.   xdi->xdi_Heads = 2;
  79.   xdi->xdi_TrackSectors = 11;
  80.   xdi->xdi_CylSectors = 22;
  81.   xdi->xdi_TotalSectors = 80 * 22;
  82.  
  83.   if((err = xadHookAccess(XADAC_INPUTSEEK, 3, 0, ai))) /* skip MSH */
  84.     return err;
  85.  
  86.   while(ai->xai_InPos < ai->xai_InSize && !err)
  87.   {
  88.     if(!(err = xadHookAccess(XADAC_READ, 3, &h, ai)) &&
  89.     !(err = xadHookAccess(XADAC_READ, 4, dat, ai)))
  90.     {
  91.       switch(h.type)
  92.       {
  93.       case XMASH_INFOTEXT: case XMASH_BANNER:
  94.         {
  95.           struct xadTextInfo *ti2;
  96.           if((ti2 = (struct xadTextInfo *) xadAllocObjectA(XADOBJ_TEXTINFO, 0)))
  97.           {
  98.         if(h.type == XMASH_BANNER)
  99.               ti2->xti_Flags |= XADTIF_BANNER;
  100.  
  101.             err = xpkDecrunch(&ti2->xti_Text, &ti2->xti_Size, ai, xadMasterBase);
  102.  
  103.             start = ai->xai_InPos;
  104.  
  105.             if(!ti)
  106.               xdi->xdi_TextInfo = ti2;
  107.             else
  108.               ti->xti_Next = ti2;
  109.             ti = ti2;
  110.           }
  111.           else
  112.             err = XADERR_NOMEMORY;
  113.         break;
  114.         }
  115.       case XMASH_ARCHIVE:
  116.         if(!(err = xadHookAccess(XADAC_READ, 36, dat, ai)) &&
  117.         !(err = xadHookAccess(XADAC_INPUTSEEK, dat[1]-28, 0, ai)))
  118.         {
  119.           if(dat[8] & (1<<25))
  120.           { /* check for password flag in every entry */
  121.             ai->xai_Flags |= XADAIF_CRYPTED;
  122.             xdi->xdi_Flags |= XADDIF_CRYPTED;
  123.           }
  124.           h.num = ((h.num+h.start) >> 1)-1;
  125.           h.start >>= 1;
  126.           if(h.start < lowcyl)
  127.             lowcyl = h.start;
  128.           if(h.num > highcyl)
  129.             highcyl = h.num;
  130.         }
  131.         break;
  132.       }
  133.     }
  134.   }
  135.  
  136.   if(lowcyl <= highcyl)
  137.   {
  138.     xdi->xdi_LowCyl  = lowcyl;
  139.     xdi->xdi_HighCyl = highcyl;
  140.   }
  141.   else
  142.     err = XADERR_INPUT;
  143.  
  144.   xdi->xdi_DataPos = start;
  145.   xdi->xdi_Flags |= XADDIF_SEEKDATAPOS;
  146.  
  147.   return err;
  148. }
  149.  
  150. ASM(LONG) xMash_UnArchive(REG(a0, struct xadArchiveInfo *ai),
  151. REG(a6, struct xadMasterBase *xadMasterBase))
  152. {
  153.   struct xMashHead h;
  154.   LONG err = 0;
  155.   ULONG size, lowcyl;
  156.   STRPTR a;
  157.  
  158.   lowcyl = ai->xai_LowCyl;
  159.  
  160.   while(!err && lowcyl <= ai->xai_HighCyl)
  161.   {
  162.     if(!(err = xadHookAccess(XADAC_READ, 3, &h, ai)) &&
  163.     !(err = xadHookAccess(XADAC_READ, 4, &size, ai)))
  164.     {
  165.       LONG endcyl, startcyl, skipbyte;
  166.  
  167.       startcyl = h.start>>1;
  168.       endcyl = ((h.start+h.num)>>1)-1;
  169.  
  170.       if(endcyl < lowcyl)
  171.         err = xadHookAccess(XADAC_INPUTSEEK, size, 0, ai);
  172.       else
  173.       {
  174.     ULONG size;
  175.         if(!(err = xpkDecrunch(&a, &size, ai, xadMasterBase)))
  176.         {
  177.       skipbyte = 0;
  178.  
  179.           if(startcyl < lowcyl)
  180.             skipbyte = (lowcyl-startcyl)*22*512;
  181.           if(endcyl > ai->xai_HighCyl)
  182.             endcyl = ai->xai_HighCyl;
  183.       size = (endcyl+1-lowcyl)*22*512;
  184.             
  185.           err = xadHookAccess(XADAC_WRITE, size, a+skipbyte, ai);
  186.           xadFreeObjectA(a, 0);
  187.           lowcyl = endcyl+1;
  188.         }
  189.       }
  190.     }
  191.   }
  192.  
  193.   return err;
  194. }
  195.  
  196. const struct xadClient xMash_Client = {
  197. NEXTCLIENT, XADCLIENT_VERSION, XADMASTERVERSION, XMASH_VERSION, XMASH_REVISION, 3,
  198. XADCF_DISKARCHIVER|XADCF_FREEDISKINFO|XADCF_FREETEXTINFO|XADCF_FREETEXTINFOTEXT,
  199. XADCID_XMASH, "xMash", (BOOL (*)()) xMash_RecogData,
  200. (LONG (*)()) xMash_GetInfo, (LONG (*)()) xMash_UnArchive, 0};
  201.  
  202. #endif /* XADMASTER_XMASH_C */
  203.